#ifdef KITSCHY_DEBUG_MEMORY 
#include "debug_memorymanager.h"
#endif

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "stdarg.h"
#include "assert.h"

#include "BList.h"

#include "symbol.h"
#include "sort.h"
#include "ontology.h"
#include "featureterm.h"
#include "FTKBase.h"

#include "SpecialTerm.h"

SpecialTerm::SpecialTerm(Sort *sort)
{
	m_sort=sort;
} /* SpecialTerm::SpecialTerm */ 


SpecialTerm::~SpecialTerm(void)
{
	m_sort=0;
} /* SpecialTerm::~SpecialTerm */ 


void SpecialTerm::createSort(Ontology *o)
{
	Sort *s;
	s=o->new_special_sort("SpecialTerm","any",0);
	s->setSpecialSeed(new SpecialTerm(s));
} /* SpecialTerm::createSort */ 


SpecialTerm *SpecialTerm::newSpecialTerm(Sort *sort,List<Symbol> *names,List<FeatureTerm> *arguments)
{
	return new SpecialTerm(sort);
} /* SpecialTerm::newSpecialTerm */ 


SpecialTerm *SpecialTerm::clone(void)
{
	return new SpecialTerm(m_sort);
} /* SpecialTerm::clone */ 


SpecialTerm *SpecialTerm::clone(class FTKBase *dm)
{
	return new SpecialTerm(m_sort);
} /* SpecialTerm::clone */ 


Sort *SpecialTerm::getSort(void)
{
	return m_sort;
} /* SpecialTerm::getSort */ 

	
List<FeatureTerm> *SpecialTerm::DSpecialization(List<FeatureTerm> *objects,Ontology *ontology,FTKBase *domain_model)
{
	return 0;
} /* SpecialTerm::DSpecialization */ 


List<FeatureTerm> *SpecialTerm::DSpecialization_b(List<FeatureTerm> *objects,Ontology *ontology,FTKBase *domain_model)
{
	return 0;
} /* SpecialTerm::DSpecialization_b */ 


List<FeatureTerm> *SpecialTerm::DGeneralization(Ontology *ontology,FTKBase *domain_model)
{
	return 0;
} /* SpecialTerm::DGeneralization */ 

  
List<FeatureTerm> *SpecialTerm::unification(FeatureTerm *f2,Ontology *ontology,FTKBase *domain_model)
{
	return 0;
} /* SpecialTerm::unification */ 


bool SpecialTerm::subsumes(FeatureTerm *f)
{
	return false;
} /* SpecialTerm::subsumes */ 


SpecialTerm *SpecialTerm::random(void)
{
	return 0;
} /* SpecialTerm::random */ 


FeatureTerm *SpecialTerm::featureValue(Symbol *feature)
{
	List<FeatureTerm> l;
	FeatureTerm *f;
	List<Symbol> l2;
	Symbol *s;

	assert(m_values.Length()==
		   m_names.Length());

	l.Instance(m_values);
	l2.Instance(m_names);
	l.Rewind();
	l2.Rewind();
	while(l.Iterate(f) && l2.Iterate(s)) {
		if (*s==*feature) return new FeatureTerm(f);
	} /* while */ 

	return 0;
} /* SpecialTerm:featureValue */ 


FeatureTerm *SpecialTerm::featureValueQuick(Symbol *feature)
{
	List<FeatureTerm> l;
	FeatureTerm *f;
	List<Symbol> l2;
	Symbol *s;

	assert(m_values.Length()==
		   m_names.Length());

	l.Instance(m_values);
	l2.Instance(m_names);
	l.Rewind();
	l2.Rewind();
	while(l.Iterate(f) && l2.Iterate(s)) {
		if (*s==*feature) return f;
	} /* while */ 

	return 0;
} /* SpecialTerm:featureValueQuick */ 


FeatureTerm *SpecialTerm::featureValue(char *feature)
{
	FeatureTerm *tmp;
	Symbol *s=new Symbol(feature);

	tmp=featureValue(s);
	delete s;

	return tmp;
} /* SpecialTerm:featureValue */ 


FeatureTerm *SpecialTerm::featureValueQuick(char *feature)
{
	FeatureTerm *tmp;
	Symbol *s=new Symbol(feature);

	tmp=featureValueQuick(s);
	delete s;

	return tmp;
} /* SpecialTerm:featureValueQuick */ 



/*
	List<FeatureTerm> *readPath(Path *path);

	char *toStringNOOS(void);
	char *toStringNOOS(FTKBase *dm); 
	static FeatureTerm *fromStringNOOS(char *s,FTKBase *m,Ontology *o);

	FeatureTerm *clone_substituting(FeatureTerm *v1,FeatureTerm *v2);
	FeatureTerm *clone_substituting(FeatureTerm *v1,FeatureTerm *v2,FTKBase *dm);
	FeatureTerm *clone_linking(FeatureTerm *v1,FeatureTerm *v2,FTKBase *dm);
	FeatureTerm *clone_keepingTrackOfNode(FeatureTerm *node,FeatureTerm **newnode,FTKBase *dm);
	FeatureTerm *clone_keepingTrackOf2Nodes(FeatureTerm *node1,FeatureTerm **newnode1,FeatureTerm *node2,FeatureTerm **newnode2,FTKBase *dm);
	int substitute(FeatureTerm *v1,FeatureTerm *v2);

	bool hasSetsP(void);
	bool hasPathEqualtiesP(void);
	bool hasPathEqualtiesP(class FTKBase *dm); 

	bool leafP(void);	

*/ 
